<template>
  <div>
    <el-row>
      <el-col :span="24" class="addRole">
        <!-- 查询 -->
        <!-- 查询 -->
        <el-popover placement="bottom-start" width="1000" style="margin-right:10px;" trigger="click">
          <el-form :inline="true" :model="search">
              <el-form-item label="图纸编号" >
                  <el-input v-model="checkSearch.drawCode"></el-input>
              </el-form-item>
              <el-form-item label="图纸" >
                  <el-input v-model="checkSearch.drawName"></el-input>
              </el-form-item>
              <el-form-item label="任务单号" >
                  <el-input v-model="checkSearch.taskNo"></el-input>
              </el-form-item>
              <el-form-item label="生产令号" >
                  <el-input v-model="checkSearch.makeNo"></el-input>
              </el-form-item>
              <el-form-item label="任务流水号" >
                  <el-input v-model="checkSearch.taskSerialNo"></el-input>
              </el-form-item>
              <el-form-item label="29所编码" >
                  <el-input v-model="checkSearch.code29"></el-input>
              </el-form-item>
              <el-form-item label="自定义编码" >
                  <el-input v-model="checkSearch.code"></el-input>
              </el-form-item>
              <el-form-item label="状态" >
                <el-select v-model="checkSearch.state" filterable clearable placeholder="请选择" >
                  <el-option value="0" label="待办"></el-option>
                  <el-option value="1" label="已办"></el-option>
                </el-select>
              </el-form-item>   
              <el-button type="primary" @click="searchBtn">确认</el-button>
          </el-form>
          <el-button slot="reference" type="primary" icon="el-icon-search">查询</el-button>
        </el-popover>  
      </el-col>
    </el-row>
    <!-- 29所列表 -->
      <el-table :data="tableCheckList" stripe border class="user-table"    style="width: 100%;">
       <!--  <el-table-column fixed  prop="reproduce" label="类型" min-width="80" align="center">
                    <template slot-scope="scope">
                        <span v-html="scope.row.reproduce ===1?'<span style=\'color:red;font-weight:bolder;padding:5px;background:yellow\'>返工</span>':'正常'" ></span>
                    </template>
          </el-table-column> -->
        <el-table-column prop="planTaskProcess.nameName" label="工序名称" sortable min-width="60"></el-table-column>

        <el-table-column prop="checkTypeDesc" label="检验类型" sortable min-width="70"></el-table-column>
        <el-table-column prop="planTaskTotal.code29" label="29所编号" sortable min-width="80"></el-table-column>
        <el-table-column prop="planTaskTotal.drawCode" label="图纸编号" sortable min-width="80"></el-table-column>
        <el-table-column prop="planTaskTotal.drawName" label="图纸名称" sortable min-width="80"></el-table-column>
        <el-table-column prop="totalNums" label="总数量" sortable min-width="40"></el-table-column>





        <!-- <el-table-column prop="content" label="检验内容" sortable min-width="120">
          <template slot-scope="scope">
            <span v-html="scope.row.content"></span>
          </template>
        </el-table-column> -->
        <el-table-column prop="resultNums" label="合格数量" sortable min-width="60"></el-table-column>
       <!--  <el-table-column prop="returnNums" label="返工数量" sortable min-width="60"></el-table-column>
        <el-table-column prop="scrapNums" label="报废数量" sortable min-width="60"></el-table-column>
        <el-table-column prop="macName" label="设备" sortable min-width="60"></el-table-column> -->

        <el-table-column prop="stateDesc" label="状态" sortable min-width="60"></el-table-column>
        <el-table-column prop="checkResult" label="检验结果" sortable min-width="60">
          <template slot-scope="scope">
            <span v-html="scope.row.checkResult==1?'合格':scope.row.checkResult==2?'不合格':''"></span>
          </template>
        </el-table-column>

        <el-table-column prop="creatorName" label="送检人" sortable min-width="60"></el-table-column>
        <el-table-column prop="createTime" label="送检时间" sortable min-width="100">
          <template slot-scope="scope">
            {{timestampToTime(scope.row.createTime,'yyyy-mm-dd hh:mm:ss')}}
          </template>
        </el-table-column>
        <el-table-column prop="startTime" label="签收时间" sortable min-width="100">
          <template slot-scope="scope">
            <!-- {{timestampToTime(scope.row.startTime,'yyyy-mm-dd hh:mm:ss')}} -->
             {{( scope.row.startTime != null && scope.row.startTime != undefined )? timestampToTime(scope.row.startTime,'yyyy-mm-dd hh:mm:ss') : ''}}
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="检验结束时间" sortable min-width="100">
          <template slot-scope="scope">
            {{( scope.row.endTime != null && scope.row.endTime != undefined )? timestampToTime(scope.row.endTime,'yyyy-mm-dd hh:mm:ss') : ''}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" v-if="scope.row.state === 0" @click="Qs(scope.row)">签收</el-button>
            <el-button type="text" @click="showDialogForCheckDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>

    <!-- 计划任务详情 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog.title" :visible.sync="dialog.isShow"  v-dialogDrag width="800px;">
          <el-form :inline="true" :model="checkObj" label-width="90px"  class="demo-ruleForm">

            
              <el-form-item label="工序名称" >
                  <el-input v-model="checkObj.planTaskProcess.nameName" disabled></el-input>
              </el-form-item>
              <el-form-item label="图纸编号" >
                  <el-input v-model="checkObj.planTaskProcess.drawNo" disabled ></el-input>
              </el-form-item> 
              <el-form-item label="送检时间" >
                  <el-date-picker  type="datetime" v-model="checkObj.createTime" disabled style="margin-top:-6px; margin-left:-1px;"></el-date-picker >
              </el-form-item>
              <br>
              <el-form-item label="开始时间" >
                  <el-date-picker  type="datetime" v-model="checkObj.startTime"  style="margin-top:-6px; margin-left:-1px;"></el-date-picker >
              </el-form-item>
              <el-form-item label="结束时间" >
                  <el-date-picker  type="datetime" v-model="checkObj.endTime"  style="margin-top:-6px; margin-left:-1px;"></el-date-picker >
              </el-form-item>  
               <br>            
              <el-form-item label="总数量" >
                  <el-input v-model="checkObj.totalNums" ></el-input>
              </el-form-item>
              <el-form-item label="合格数量" >
                  <el-input v-model="checkObj.resultNums"  ></el-input>
              </el-form-item>
              <br>
              <el-form-item v-if="checkObj.checkResult==2" label="报废数量" >
                  <el-input v-model="checkObj.scrapNums" ></el-input>
              </el-form-item>
              <el-form-item v-if="checkObj.checkResult==2" label="返工数量" >
                  <el-input v-model="checkObj.returnNums" ></el-input>
              </el-form-item>
              <br>
              <el-form-item label="结果" >
                <span v-if="checkObj.checkResult==1?[checkObj.scrapNums='',checkObj.returnNums='',checkObj.remark='']:''">
                </span>
                  <el-select v-model="checkObj.checkResult" >
                    <el-option label="合格" value="1"></el-option>
                    <el-option label="不合格" value="2"></el-option>
                  </el-select>
              </el-form-item>
              <br> 
              <el-form-item label="设备" >
                <el-select v-model="checkObj.mac" filterable clearable placeholder="请选择" >
                  <el-option
                    v-for="item in machineList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
                  <!-- <el-input v-model="checkObj.mac"></el-input> -->
              </el-form-item>
              <br>
              <el-form-item label="检验类型" >
                  <el-input v-model="checkObj.checkTypeDesc" ></el-input>
              </el-form-item>
              <!-- <el-form-item label="状态" >
                <span v-if="checkObj.stateStr = checkObj.stae==0?'待检':'已检'"></span>
                  <el-input v-model="checkObj.stateStr" :value="checkObj.stae==0?'待检':'已检'"></el-input>
              </el-form-item> -->
              <br>
              <el-form-item label="检验内容" >
                  <el-input v-model="checkObj.content" type="textarea"  :autosize="{ minRows: 5, maxRows: 10}"></el-input>
              </el-form-item>   
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <el-form-item  v-if="checkObj.checkResult==2" label="异常信息描述" >
                  <el-input v-model="checkObj.remark" type="textarea"  :autosize="{ minRows: 5, maxRows: 10}"></el-input>
              </el-form-item>   
              <div style="width:100%;height:40px;border:0px solid red;text-align:center;margin-top:20px;">
                <el-button type="primary" @click="updateCheck(1)">确定</el-button>
                <el-button type="danger" @click="[dialog.isShow=false]">关闭</el-button>
              
              </div>                             
          </el-form>      
    </el-dialog>
  </div>
</template>
<script>
import planApi from 'plugins/axios/planApi.js';
import baseApi from 'plugins/axios/baseApi.js';
import materielApi from 'plugins/axios/materielApi.js';
import uploadList from 'views/components/uploadList.vue' /**1-图纸上传、2-工艺上传、3-图形文件上传 的列表组件 */
import productionPlanList from 'views/components/productionPlanList.vue' /**29所列表组件 */
import taskDetail29 from 'views/components/taskDetail29.vue' /**29所任务详情组件 */
import processPlanList29 from 'views/components/processPlanList29.vue' /**29所工序列表组件 */
import processPlanDetail29 from 'views/components/processPlanDetail29.vue' /**29所工序详情组件 */
import processPlanList from 'views/components/processPlanList.vue' /**工艺编制列表组件 */
import processPlanDetail from 'views/components/processPlanDetail.vue' /**新增编辑工艺编制组件 */
import programList from 'views/components/programList.vue' /**编程详情组件 */
import productionRecordList from 'views/components/productionRecordList.vue' /**生产记录列表 */
import testProcess from 'views/components/testProcess.vue' /**检验工序 */

export default {
  components: {
    uploadList,
    productionPlanList,
    taskDetail29,
    processPlanList29,
    processPlanDetail29,
    processPlanList,
    processPlanDetail,
    programList,
    productionRecordList,
    testProcess
  },
  data(){
    return {
      currentPage:1,
      pageSize:10,
      total:0,
      status:'0',
      postData:{
        isUploadDraw:1,
        isMaterialArrvie:1,
        isMaterialTailor:1,
        isFinishProcess:1
      },
      machineList:[],
      tableCheckList:[],
      machineAllList:[],/**所有机器列表 */
      search:{
        drawCode:"",
        makeNo:"",
        code:""
      },
      checkSearch:{

      },
      checkObj:{
        planTaskProcess:{

        },
      },
      dialog:{/**弹框配置 */
        title:'',
        isShow:false,
        type:'',
        formData:{},
        activeName:'2',
        otherUpDataData:{},
        tableData:[],
        drawCode:''
      },
      dialog1:{
        title:'',
        isShow:false,
        formData:{},
        rules:{}
      },
      programDialog:{/**程序列表 */
        tid:'',
        title:'',
        isShow:false,
      },
      dialog2:{
        type:'',
        title:'',
        isShow:false,
        formData:{}
      }
    }
  },
  mounted(){
    this.checkSearch.state = this.$route.query.status;
    this.queryTableCheckList();
    this.queryMachineList();
  },
  created(){
    
  },
  watch: {
    $route(){
      this.status = this.$route.query.status;
      this.checkSearch.state = this.$route.query.status;
      this.search.drawCode="";
      this.search.makeNo="";
      this.search.code="";
      
      this.queryTableCheckList();
    }
  },
  methods:{
    Qs(row){
      let self = this;
      planApi.checkQs(row.id).then(res=>{
        self.$message({message:'签收成功!',type:'success'});
        self.queryTableCheckList();
      });
    },
    //查询机器列表    
    queryMachineList(){
      let self = this;
      planApi.queryMachineList().then(res=>{
        self.machineList = res.content;
      });
    },
    showDialogForCheckDetail(row){
      let self = this;
      self.dialog.isShow = true;
      self.checkObj =  row;
    },
    searchBtn(){
      let self = this;
      self.queryTableCheckList();
    },
    queryTableCheckList(){
      let self = this; 
      let param = {
        currentPage:self.currentPage,
        pageSize:self.pageSize,
        taskNo:self.checkSearch.taskNo,
        taskSerialNo:self.checkSearch.taskSerialNo,
        makeNo:self.checkSearch.makeNo,
        drawCode:self.checkSearch.drawCode,
        drawName:self.checkSearch.drawName,
        code29:self.checkSearch.code29,
        code:self.checkSearch.code,
        state:self.checkSearch.state,
        processDetailId:null,
      }
      planApi.selectCheck(param).then(res=>{
          self.tableCheckList = res.content.records;
          self.total = res.content.total;
      });
    },
    updateCheck(type){
      let self = this; 
      self.checkObj.state = type;
      planApi.updateCheck(self.checkObj).then(res=>{
          // self.tableCheckList = res.content.records;
          // self.total = res.content.total;
          self.dialog.isShow = false;
          self.$message({
            message:'操作成功!',
            type:'success'
          });
          self.queryTableCheckList();
      });
    },
    getTablList(){/**计划列表 */
      let self = this;
      self.postData.drawCode=self.search.drawCode;
      self.postData.makeNo=self.search.makeNo;
      self.postData.code=self.search.code;
      self.postData.state= self.status;
      self.$refs.tableList29.get29TableList()
    },

    showDialog(type,row){
      this.dialog.activeName='8';
      this.dialog.type = type;
      switch(type){
        case 'insert':
          this.dialog.isShow=true;
          this.dialog.formData={};
          this.dialog.title = '新增计划任务';
          break;
        case 'update':
          this.dialog.isShow=true;
          this.dialog.formData = row;
          this.dialog.title = '计划详情';
          this.dialog.drawCode = row.drawCode;
          this.dialog.otherUpDataData.drawNo=row.drawCode;
          break;
        case 'print':
           this.dialog.formData = row;
           this.$refs.print1.getCgPdfData(row.id);
          break;
      } 
    },
    showDialog1(type,row){
      this.dialog1.isShow=true;
      this.dialog1.type=type;
      switch(type){
        case 'insert':
          this.dialog1.formData={};
          this.dialog1.title = '新增29所工艺详情';
          break;
        case 'update':
          this.dialog1.formData = row;
          this.dialog1.title = '编辑29所工艺详情';
        break;
      }
    },
    /**详情切换tab*/ 
    dialogHandleClick(){
      let self = this;
      switch(self.dialog.activeName){
        case '2':
          self.$refs.processPlanList29Ref.getProcessPlanList();
          break;
        case '3':
          self.$refs.drawing.getTableList();
          break;
        case '4':
          self.$refs.technology.getTableList();
          break;
        case '5':
          self.$refs.graphicsFile.getTableList();
          break;
        case '6':
          self.$refs.processPlanListRef.getProcessPlanList();
          break;
        case '7':
          /**生产工序记录*/
          this.$refs.productionRecordListRef.getRecordList();
          break;
        case '8':
          /**检验工序记录*/
         this.$refs.testProcessRef.getRecordList()
          break;
      }
    },
    /***确认编程完成 */
    confirmHandle(row){
      let self  = this;
       self.$confirm('是否确认编程完成?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          materielApi.finishProgram(row.id).then(res=>{
            self.$message.success("确认成功")
            self.getTablList();
          })
        }).catch(()=>{})
    },
    editSuccess(){
      this.dialog2.isShow=false;
      this.$refs.processPlanListRef.getProcessPlanList();
      this.$message.success(`${this.dialog2.title}成功`)
    },
    dialogOpened(){
       this.dialog.type==='update'? this.$refs.testProcessRef.getRecordList():'';
    },
    dialogClosed(){
     this.$refs.testProcessRef.getRecordList();
    },
    /**显示编程页面列表*/ 
    showProgramDialog(row){
      let self= this;
      self.programDialog.isShow = true;
      self.programDialog.title =`${row.nameName}详情`;
      self.programDialog.programObj = {
        data:row,
        tid:row.id,
        drawCode:row.drawNo,
        processId:row.name
      };
    },
    openedProgramDialog(){
      this.$refs.programDetail.getProgramList();
    },
    handleSizeChange(size) {
      this.pageSize = size;
      this.queryTableCheckList();
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage;
      this.queryTableCheckList();
    },
  }
}
</script>
<style lang="stylus" scoped>
  .addRole
    padding-bottom 10px
  .content-rowspan div
    padding-left: 13px;
    line-height: 46px;
    border-bottom: 1px solid #ECEDEE;
    &:last-child
      border-bottom:none
</style>
